﻿Imports System.Collections.ObjectModel

Public Class DefinitionViewerVm
    Inherits ViewModelBase

    Public Sub New()
        Arguments = New ObservableCollection(Of ArgData)
    End Sub

    Public Sub Update(token As Token, obj As RawObject)
        If token IsNot Nothing AndAlso obj IsNot Nothing Then
            Dim usage As TokenUsage = TokenDictionary.Instance.GetUsage(token.Name, obj.TypeCode)
            Name = token.Name
            ArgumentsAsString = token.ArgumentsAsString

            If usage IsNot Nothing Then
                If Not String.IsNullOrWhiteSpace(usage.Description) Then
                    Description = usage.Description
                Else
                    Description = "<no description>"
                End If

                Arguments.Clear()
                For Each arg As ArgumentDefinition In usage.Arguments
                    Arguments.Add(New ArgData With {.Name = arg.Name,
                                                    .Type = arg.Type.ToString,
                                                    .Description = arg.Description})
                Next
            End If
        End If
    End Sub

    Private mName As String
    Public Property Name As String
        Get
            Return mName
        End Get
        Set(value As String)
            If mName <> value Then
                mName = value
                RaisePropertyChanged("Name")
            End If
        End Set
    End Property

    Private mArgumentsAsString As String
    Public Property ArgumentsAsString As String
        Get
            Return mArgumentsAsString
        End Get
        Set(value As String)
            If mArgumentsAsString <> value Then
                mArgumentsAsString = value
                RaisePropertyChanged("ArgumentsAsString")
            End If
        End Set
    End Property

    Private mDescription As String
    Public Property Description As String
        Get
            Return mDescription
        End Get
        Set(value As String)
            If mDescription <> value Then
                mDescription = value
                RaisePropertyChanged("Description")
            End If
        End Set
    End Property

    Public Property Arguments As ObservableCollection(Of ArgData)

    Public Class ArgData
        Public Property Name As String
        Public Property Type As String
        Public Property Value As String
        Public Property Description As String
    End Class
End Class
